// pages/mobile/mobile.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    opacity: 1    //设置透明度  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: 'https://www.eddieby.top/byte_gd/public/index.php/index/user/get_traffic',
      data: {
        port: '134d'
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (response) {
        console.log(response.data)
      }
    });
  },
  getPhoneNumber: function (e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
    wx.request({
      url: 'https://www.eddieby.top/gd/public/index.php/index/index/WXBizDataCrypt',
      data: {
        sessionKey: wx.getStorageSync('session_key'),
        encryptedData: e.detail.encryptedData,
        iv: e.detail.iv
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (response) {
        wx.request({
          url: 'https://www.eddieby.top/gd/public/index.php/index/index/bindmobile',
          data: {
            openid: wx.getStorageSync('openid'),
            mobile: response.data.purePhoneNumber,
          },
          method: 'POST',
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (response1) {
            if (response1.data=="success:true") {
              wx.showToast({
                title: '绑定成功',
                icon: 'success',
                duration: 2000
              })
              wx.navigateBack({
                delta: 1
              })
            }
          }
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  goRules: function () {
    wx.downloadFile({
      url: 'https://eddieby.top/document/rules.doc',
      success: function (res) {
        var filePath = res.tempFilePath
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log('打开文档成功')
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  touch: function () {
    this.setData({
      opacity: 0.4
    })
  },
  touched: function () {
    this.setData({
      opacity: 1
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})